package com.neu.envprotection.airQuality.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.neu.envprotection.airQuality.dao.entity.AirQuality;
import com.neu.envprotection.airQuality.dao.mapper.AirQualityMapper;
import com.neu.envprotection.airQuality.dto.req.AirQualityReqDto;
import com.neu.envprotection.airQuality.dto.req.UserSelectReqDto;
import com.neu.envprotection.airQuality.dto.resp.*;
import com.neu.envprotection.airQuality.service.InvestigatorService;
import com.neu.envprotection.common.resp.RestResp;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 网格员(调查员)业务
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class InvestigatorServiceImpl implements InvestigatorService {
    private final AirQualityMapper airQualityMapper;

    @Override
    public RestResp<List<AirQualityRespDto>> getAirQuality(UserSelectReqDto userSelectReqDto){
        return RestResp.ok(airQualityMapper.selectAirQualityListById(userSelectReqDto));
    }

    @Override
    public RestResp<Integer> submitAirQuality(AirQualityReqDto airQualityReqDto) {
        return RestResp.ok(airQualityMapper.updateAirQualityByReq(airQualityReqDto));
    }

    @Override
    public RestResp<List<AirQHistoryRespDto>> getAirQHistoryById(UserSelectReqDto userSelectReqDto){
        return RestResp.ok(airQualityMapper.getAirQHistoryById(userSelectReqDto));
    }

    @Override
    public RestResp<Void> addAirQuality(AirQuality airQuality) {
        airQualityMapper.insert(airQuality);
        return RestResp.ok();
    }

    @Override
    public RestResp<List<GetProvinceAQIRespDto>> getProvinceAQI() {
        return RestResp.ok(airQualityMapper.getProvinceAQI());
    }

    @Override
    public RestResp<List<GetAQIDistributionRespDto>> getAQIDistribution() {
        return RestResp.ok(airQualityMapper.getAQIDistribution());
    }

    @Override
    public RestResp<List<GetAQITrendRespDto>> getAQITrend() {
        List<GetAQITrendRespDto> aqiTrend = airQualityMapper.getAQITrend();
        for (GetAQITrendRespDto re : aqiTrend) {
            int year = re.getYear();
            int month = re.getMonth();
            re.setYearMonth(year + "-" + month);
        }
        return RestResp.ok(aqiTrend);
    }
}
